import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { ApiService, urlService } from 'src/app/core/api';
import { CommonResponse } from 'src/app/model';
import { environment } from 'src/environments/environment';

@Injectable()
export class PasswordResetService {


  sendCodeForRePwd(data: { mobile: string} | { email: string}): Observable<CommonResponse<string>> {
    return this.api.post<CommonResponse<string>>(urlService(environment.type, '修改登入密码时(未登入) 发送验证码'), data);
  }

  resetPassword(data: {
    verifyCode: string,
    newPwd: string,
    newConfirmPwd: string
  } & ({ mobile: string} | { email: string})) {
    return this.api.post<CommonResponse<string>>(urlService(environment.type, '修改登入密码(未登入) 通过手机验证码'), data);
  }

  error(error: any) {
    this.api.goToWhere(error);
  }

  constructor(
    private api: ApiService
  ) { }
}
